

package cn.shengchao.examstar.product.ohs.local.message;

import cn.shengchao.examstar.product.domain.entity.Course;
import cn.shengchao.examstar.product.domain.entity.Teacher;
import lombok.Data;

import java.math.BigDecimal;
import java.util.List;

@Data
public class CourseInfoDto {

    private Long id;
    //名称
    private String name;
    //图片
    private String imgUrl;
    private String cardUrl;
    //购买人数
    private Integer payNum;
    private Integer courseType;
    private Double classHour;
    //课程知识点数量
    private String KnowledgeNodeNum;
    //课程评分
    private Double score;
    //描述
    private String description;
    //教师描述
    private List<Teacher> teacher;
    //详情
    private String details;
    //价格
    private BigDecimal price;
    //折扣价格
    private BigDecimal discountPrice;
    private Integer sort;
    private String specificationType;
    private String status;

    public static CourseInfoDto of(Course course) {
        CourseInfoDto courseInfoDto = new CourseInfoDto();
        courseInfoDto.setId(course.getId());
        courseInfoDto.setCardUrl(course.getCardUrl());
        courseInfoDto.setName(course.getName().getValue());
        courseInfoDto.setImgUrl(course.getImageUrl());
        courseInfoDto.setPayNum(course.getActualPurchaseNum());
        courseInfoDto.setKnowledgeNodeNum(course.getKnowledgeNodeNum().toString());
        courseInfoDto.setScore(course.getScore());
        courseInfoDto.setDescription(course.getDescription());
        courseInfoDto.setCourseType(course.getCourseType());
        courseInfoDto.setDetails(course.getDetails());
        courseInfoDto.setPrice(course.getPrice().getPrice());
        courseInfoDto.setDiscountPrice(course.getDiscountPrice().getPrice());
        courseInfoDto.setSort(course.getSort());
        if (course.getSpecificationType() != null) {
            courseInfoDto.setSpecificationType(String.join(",", course.getSpecificationType()));
        }
        courseInfoDto.setStatus(String.valueOf(course.getStatus().getValue()));
        courseInfoDto.setClassHour(course.getClassHour());
        return courseInfoDto;
    }
}
